package demo;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;

public class Test {
    public static void main5(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.addLast(1);
        list.addLast(1);
        list.addLast(1);
        list.addLast(2);
        list.add(2,3);
        list.add(0,9);
        list.addLast(6);
        System.out.println("====for循环====");
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");

        }
        System.out.println();
        System.out.println("====for each循环====");
        for(Integer x : list){
            System.out.print(x + " ");

        }
        System.out.println();
        System.out.println("====iterator====");
        Iterator<Integer> it = list.iterator();
        while(it.hasNext()){
            System.out.print(it.next() + " ");

        }
        System.out.println();
        System.out.println("====listIterator反向输出====");
        ListIterator<Integer> it2 = list.listIterator(list.size());
        while(it2.hasPrevious()){
            System.out.print(it2.previous() + " ");

        }
        System.out.println();
    }
    public static void main4(String[] args) {
        //双向链表开始
        MyLinkedList list = new MyLinkedList();
        list.addLast(1);
        list.addLast(1);
        list.addLast(1);
        list.addLast(2);
        list.addFirst(6);
        list.addIndex(2,3);
        list.addIndex(0,9);
        list.addLast(6);
        list.display();
        list.remove(1);
        list.display();
        list.removeAllKey(6);
        list.display();
        list.clear();
        list.display();
    }








    public static void main3(String[] args) {
        SingleLinkedLis list1 = new SingleLinkedLis();
        list1.addLast(1);
        list1.addLast(2);

        list1.addLast(4);

        SingleLinkedLis list2 = new SingleLinkedLis();
        list2.addLast(1);

        list2.addLast(3);
        list2.addLast(4);
        SingleLinkedLis.ListNode ret = list2.mergeTwoLists(list1.head,list2.head);
        list1.display(ret);
    }
    public static void main2(String[] args) {
        SingleLinkedLis list = new SingleLinkedLis();
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(2);
        list.addLast(1);
        System.out.println(list.chkPalindrome(list.head));
    }
    public static void main1(String[] args) {
        SingleLinkedLis list = new SingleLinkedLis();
        //list.creatList();

        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);
        list.addLast(5);
        list.addFirst(1);
        list.addLast(99);
        list.addIndex(3,88);
        System.out.println(list.contains(99));

        list.display();

        System.out.println(list.size());
        list.addLast(1);
        list.remove(88);
        list.display();


        list.removeAllKey(1);
        list.display();
//        list.clear();
//        list.display();

        SingleLinkedLis.ListNode ret = list.reverseList();
        list.display(ret);

        SingleLinkedLis.ListNode ret1 = list.middleNode();
        System.out.println(ret1.val);
    }
}
